export default {
  changeFullScreen (state, flag) {
    state.isFullScreen = flag
    if (flag) {
      state.isShowMiniplay = false
      state.isShowList = false
    }
  },
  setMiniplay (state, flag) {
    state.isShowMiniplay = flag
    if (flag) {
      state.isFullScreen = false
      state.isShowList = false
    }
  },
  setPlay (state, flag) {
    state.isPlay = flag
  },
  setMode (state, flag) {
    state.mode = flag
  },
  isShowList (state, flag) {
    state.isShowList = flag
  },
  setsongs (state, list) {
    state.songs = list
  },
  setlyric (state, lyric) {
    state.lyric = lyric
  },
  setdel (state, index) {
    if (index !== undefined) {
      state.songs.splice(index, 1)
    } else {
      state.songs = []
    }
    if (index < state.currentIndex) {
      state.currentIndex = state.currentIndex - 1
    }
    if (state.songs.length === 0) {
      state.isFullScreen = false
      state.isShowMiniplay = false
      state.isShowList = false
    }
  },
  setIndex (state, index) {
    if (index < 0) {
      index = state.songs.length - 1
    } else if (index > state.songs.length - 1) {
      index = 0
    }
    state.currentIndex = index
  },
  setCurrentTime (state, time) {
    state.currentTime = time
  },
  setFavoriteSong (state, song) {
    const res = state.favoriteSong.find(function (value) {
      return value.id === song.id
    })
    if (res === undefined) {
      state.favoriteSong.push(song)
    }
  },
  FavoriteList (state, list) {
    state.favoriteSong = list
  },
  sethistorySong (state, song) {
    const res = state.historyList.find(function (value) {
      return value.id === song.id
    })
    if (res === undefined) {
      if (state.historyList.length > 30) {
        state.historyList.splice(0, 1)
      }
      state.historyList.push(song)
    }
  },
  sethistoryList (state, list) {
    state.historyList = list
  }
}
